package com.jd.financeweb.controller;

import com.alibaba.fastjson.JSON;
import com.jd.financeweb.pojo.dto.GetRepayRecordDTO;
import com.jd.financeweb.service.LoadService;
import com.jd.financeweb.service.impl.LoadServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/userRepayRecord")
public class RepayRecordController extends HttpServlet {


    LoadService loadService = new LoadServiceImpl();

    /**
     * 根据uid查询还款记录
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //用户身份证号
        String idNo = req.getParameter("idNo");

        List<GetRepayRecordDTO> response=loadService.userRepayRecord(idNo);
        String jsonString = JSON.toJSONString(response);

        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        out.println(jsonString);
        out.flush();
        out.close();
    }
}
